package org.example.lease.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.example.lease.model.entities.FacilityInfo;
import org.example.lease.model.enums.ItemType;
import org.example.lease.model.result.Result;
import org.example.lease.service.FacilityInfoService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 宋孟林
 * @description
 * @date: 2025/5/16 7:54
 */
@RestController
@RequestMapping("/admin/facility")
@Slf4j
@Tag(name = "配套管理")
public class FacilityController {
    @Resource
    private FacilityInfoService facilityInfoService;

    @Operation(summary = "根据类型查找配套列表")
    @GetMapping("/list")
    public Result<List<FacilityInfo>> listFacility(@RequestParam(required = false) ItemType itemType){
        List<FacilityInfo> facilityInfos = facilityInfoService.listFacility(itemType);
        return Result.ok(facilityInfos);
    }

    @Operation(summary = "根据实体修改配套信息")
    @PostMapping("/saveOrUpdate")
    public Result<?> saveOrUpdate(@RequestBody FacilityInfo facilityInfo){
        facilityInfoService.saveOrUpdate(facilityInfo);
        return Result.ok();
    }

    @Operation(summary = "根据id删除配套")
    @DeleteMapping("/removeById")
    public Result<?> removeFacilityById(@RequestParam Long id){
        facilityInfoService.removeById(id);
        return Result.ok();
    }

}
